#include <bits/stdc++.h> // 20 pts
using namespace std;

const int N = 2e5 + 5, A = 1e6 + 5;
int T;
int n, a[N], ans, sum;

int main () {
    freopen("color.in", "r", stdin);
    freopen("color.out", "w", stdout);
    cin >> T;
    while (T--) {
        cin >> n;
        ans = sum = 0;
        for (int i = 1; i <= n; i++) {
            cin >> a[i];
        }
        if (n <= 15){
            for (int i = 0; i < (1 << n); i++) {
                int c[2] = {0, 0};
                sum = 0;
                for (int j = 1; j <= n; j++) {
                    int color = (i >> (j - 1)) & 1;
                    if (!c[color]) {
                        c[color] = j;
                        continue;
                    }
                    else {
                        if (a[c[color]] == a[j]) sum += a[j];
                        c[color] = j;
                    }
                }
                ans = max (sum, ans);
            }
        }
        cout << ans << endl;
    }
    return 0;
}